Moduł:Variant
Used by Template:Variant -- local p = {} local title = string.lower(mw.title.getCurrentTitle().text) local values = { 'main-hand' = 'mh', 'mainhand' = 'mh', 'off-hand' = 'oh', 'offhand' = 'oh', 'superior' = 'tier', 'inferior' = 'tier', 'achto' = 'tier', 'attuned' = 'tier', 'enhanced' = 'tier', 'refined' = 'tier', 'augmented' = 'augmented', dyed' = 'dyed', 'barrows' = 'dyed', dyed' = 'dyed', 'shadow' = 'dyed', dyed' = 'dyed', 'third-age' = 'dyed', age dyed' = 'dyed', age' = 'dyed', dyed' = 'dyed', 'blood' = 'dyed', 'red' = 'dyed', 'orange' = 'dyed', 'yellow' = 'dyed', 'green' = 'dyed', 'blue' = 'dyed', 'purple' = 'dyed', 'black' = 'dyed', 'white' = 'dyed', } -- as above but specifically tt dyes for correct auto-parsing local tt_dyes = { dyed' = true, 'barrows' = true, dyed' = true, 'shadow' = true, dyed' = true, 'third-age' = true, age dyed' = true, age' = true, dyed' = true, 'blood' = true, } function p.main(frame) local args = frame:getParent().args local links = {} local misc = {} local ret = {} ret.mh = {} ret.oh = {} ret.tier = {} ret.augmented = {} ret.dyed = {} for key,value in pairs(args) do local kind, item = '', '' local kind_t -- numeric key => unnamed param if tonumber(key) then -- the value is the kind and the item is "kind PAGENAME" kind = string.lower(value) else -- else kind is key and item is value kind = string.lower(key) item = value end -- apparently linebreaks aren't actually trimmed by the parser (when they really should be)???? item = mw.text.trim(item) kind = mw.text.trim(kind) if valueskind then linkskind = getLink(kind, item) else table.insert(misc, getLink(kind, item)) end end -- put links into order for i,v in pairs(values) do if linksi then table.insert(retv,linksi) end end local _ret = mw.html.create() if ret.mh1 then _ret:tag('div') :addClass('seealso') :wikitext('For this item\'s main-hand variant, see ') :wikitext(ret.mh1 .. '.') :done() end if ret.oh1 then local _slot if title:find('off%-?hand') then _slot = 'main-hand' else _slot = 'off-hand' end _ret:tag('div') :addClass('seealso') :wikitext(string.format('For this item\'s %s variant, see ',_slot)) :wikitext(ret.oh1 .. '.') :done() end if ret.tier1 then _ret:tag('div') :addClass('seealso') :wikitext('For other variants of this item, see ') :wikitext(table.concat(ret.tier,', ') .. '.') :done() end if ret.augmented1 then local augtext if title:find('augmented') then augtext = 'For this item\'s standard variant, see ' else augtext = 'For this item\'s augmented variant, see ' end _ret:tag('div') :addClass('seealso') :wikitext(augtext) :wikitext(table.concat(ret.augmented) .. '.') :done() end if ret.dyed1 then _ret:tag('div') :addClass('seealso') :wikitext('For this item\'s (un)dyed variants, see ') :wikitext(table.concat(ret.dyed,', ') .. '.') :done() end if misc1 then _ret:tag('div') :addClass('seealso') :wikitext('For other variants of this item, see ') :wikitext(table.concat(misc,', ') .. '.') :done() end return _ret end function getLink(kind, item) title = title2 or title local strippedtitle = string.gsub(string.lower(title), '-', '') local strippedkind = string.gsub(kind, '-', '') if item '' then if string.find(strippedtitle, strippedkind) ~= nil then item = string.gsub(strippedtitle, strippedkind, '') if tt_dyeskind then item = string.gsub(title, ' %(' .. strippedkind .. '%)', '') end if kind 'off-hand' then kind = 'main-hand' elseif kind 'superior' then kind = 'inferior' elseif tt_dyeskind then kind = 'undyed' else kind = 'non-'..kind end else if tt_dyeskind then item = string.gsub(title, '%(.*%)$', string.format('(%s)', kind)) else item = kind..' '..title end end else if string.find(strippedtitle, strippedkind) ~= nil then if tt_dyeskind then kind = 'undyed' else kind = 'non-'..kind end end end if kind:find('hand') or kind:find('augment') then return string.format('%s',item) else if tt_dyeskind then if kind ~= 'blood' and kind ~= 'blood dyed' then if kind:find('third') then kind = 'Third Age' else kind = string.upper(string.sub(kind,1,1))..string.lower(string.sub(kind,2,-1)) end end end return string.format('%s',item,kind) end end return p